package com.shiguiwu.springmybatis.mybatis;

import com.shiguiwu.springmybatis.mybatis.mapper.Book1Mapper;
import com.shiguiwu.springmybatis.mybatis.mapper.BookMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @description: 类型处理器，这个你得会玩！
 * @author: stone
 * @date: Created by 2021/6/30 23:01
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.mybatis
 */
@Slf4j
public class TypeHandlerTests {

    public static void main(String[] args) {
        SqlSession sqlSession = MapperTests.FACTORY.openSession(true);
        BookMapper bookMapper = sqlSession.getMapper(BookMapper.class);
        BookMapper bookMapper2 = sqlSession.getMapper(BookMapper.class);

        sqlSession.close();

        log.info("{}", sqlSession);


        Book book = new Book();
        book.setBookName("三国演义");
        book.setSex(SexTypeHandle.Sex.MAN);
        bookMapper.insert(book);
//        sqlSession.close();
        SqlSession sqlSession2= MapperTests.FACTORY.openSession(true);

        log.info("{}", bookMapper == bookMapper2);
        Book1Mapper book1Mapper = sqlSession2.getMapper(Book1Mapper.class);
        Book book1 = new Book();
        book1.setBookName("三国演义");
        book1.setSex(SexTypeHandle.Sex.MAN);
        book1Mapper.insert(book1);
        log.info("{}", sqlSession == sqlSession2);

        List<Book> bookList = bookMapper.getBookList();
        log.info("{}", bookList);
    }
}
